package com.mk.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mk.entity.Pet;
import com.mk.entity.Vaccine;
import com.mk.result.Result;
import com.mk.service.IPetService;
import com.mk.service.IVaccineService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 疫苗接种情况业务
 */
@RestController
@RequestMapping("/user/vaccine")
@RequiredArgsConstructor
public class VaccineController {

    private final IVaccineService vaccineService;

    /**
     * 疫苗接种情况登记
     * @param vaccine
     * @return
     */
    @CrossOrigin
    @PostMapping("/save")
    public Result saveVaccine(@RequestBody Vaccine vaccine) {
        vaccine.setStatus(Vaccine.NORMAL);
        vaccine.setCreateTime(LocalDateTime.now());
        vaccine.setUpdateTime(LocalDateTime.now());
        vaccineService.save(vaccine);
        return Result.success();
    }

    /**
     * 根据宠物id获取所有疫苗接种情况
     * @param petId
     * @return
     */
    @CrossOrigin
    @GetMapping("/ids")
    public Result<List<Vaccine>> getAllVaccines(Long petId) {
        List<Vaccine> list = vaccineService.list(new LambdaQueryWrapper<Vaccine>()
                .eq(Vaccine::getPetId, petId));
        return Result.success(list);
    }

    /**
     * 根据id删除疫苗接种情况信息
     * @param id
     * @return
     */
    @CrossOrigin
    @DeleteMapping("/delete/{id}")
    public Result deleteVaccine(@PathVariable Long id) {
        vaccineService.removeById(id);
        return Result.success();
    }
}
